<template>
  <d2-container>
    <template slot="header">新增计量器具</template>
    <el-form ref="form" :model="form" label-width="90px">
      <el-col :span="24">基本信息</el-col>
      <el-col :span="6">
        <el-form-item label="类别代码">
          <el-select v-model="form.categoryCode" placeholder="" size="mini">
            <el-option
              v-for="item in utensilTypeList"
              :key="'applianceId'+item.applianceId"
              :label="item.applianceName"
              :value=item.applianceId
            ></el-option>
          </el-select>
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item label="器具名称">
          <el-input v-model="form.applianceName" placeholder="" size="mini"></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item label="型号规格">
          <el-input v-model="form.model" placeholder="" size="mini"></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item label="测量范围">
          <el-input v-model="form.measureRange" placeholder="" size="mini"></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item label="准确度等级">
          <el-input v-model="form.accuracyDegree" placeholder="" size="mini"></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item label="类型">
          <el-select v-model="form.applianceType" placeholder="" size="mini">
            <el-option key="'applianceType' + 1" label="标准器具" value=1></el-option>
            <el-option key="'applianceType' + 2" label="非标准器具" value=2></el-option>
          </el-select>
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item label="检测部门">
          <el-select v-model="form.departId" placeholder="" size="mini">
            <el-option
              v-for="item in departmentList"
              :key="'departId' + item.departId"
              :label="item.departName"
              :value=item.departId
            ></el-option>
          </el-select>
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item label="检测方式">
          <el-select v-model="form.detectionMethod" placeholder="" size="mini">
            <el-option key="'detectionMethod' + 1" label="送检" value="1"></el-option>
            <el-option key="'detectionMethod' + 2" label="现场" value="2"></el-option>
          </el-select>
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item label="检测参数">
          <el-input v-model="form.detectionParameter" placeholder="" size="mini"></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item label="检测耗时">
          <el-input v-model="form.detectionDuration" placeholder="" size="mini"></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item label="状态">
          <el-select v-model="form.status" placeholder="" size="mini">
            <el-option key="'status' + 1" label="启用" value="1"></el-option>
            <el-option key="'status' + 0" label="禁用" value="2"></el-option>
          </el-select>
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item label="检测周期">
          <el-select v-model="form.certificateJdzq" placeholder="" size="mini">
            <el-option key="'certificateJdzq' + 1" label="1月" value="1"></el-option>
            <el-option key="'certificateJdzq' + 2" label="2月" value="2"></el-option>
            <el-option key="'certificateJdzq' + 3" label="3月" value="3"></el-option>
            <el-option key="'certificateJdzq' + 4" label="4月" value="4"></el-option>
            <el-option key="'certificateJdzq' + 6" label="6月" value="6"></el-option>
            <el-option key="'certificateJdzq' + 8" label="8月" value="8"></el-option>
            <el-option key="'certificateJdzq' + 10" label="10月" value="10"></el-option>
            <el-option key="'certificateJdzq' + 12" label="1年" value="12"></el-option>
            <el-option key="'certificateJdzq' + 24" label="2年" value="24"></el-option>
            <el-option key="'certificateJdzq' + 36" label="3年" value="36"></el-option>
            <el-option key="'certificateJdzq' + 60" label="5年" value="60"></el-option>
            <el-option key="'certificateJdzq' + 120" label="10年" value="120"></el-option>
          </el-select>
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item label="是否分包">
          <el-select v-model="form.isSubpackage" placeholder="" size="mini">
            <el-option key="'isSubpackage' + 0" label="否" value="0"></el-option>
            <el-option key="'isSubpackage' + 1" label="是" value="1"></el-option>

          </el-select>
        </el-form-item>
      </el-col>
      <el-col :span="24">
        <el-form-item label="备注">
          <el-input v-model="form.remark" placeholder="" size="mini"></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="24">费用信息</el-col>
      <el-col :span="6">
        <el-form-item label="检测费">
          <el-input v-model="form.detectionFee" placeholder="" size="mini"></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item label="监测点">
          <el-input v-model="form.detectionPoint" placeholder="" size="mini"></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item label="收费单位">
          <el-input v-model="form.chargeUnit" placeholder="件" size="mini"></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item label="是否可折扣">
          <el-select v-model="form.isDiscount" placeholder="" size="mini">
            <el-option key="'isDiscount' + 1" label="是" value="1"></el-option>
            <el-option key="'isDiscount' + 0" label="否" value="2"></el-option>
          </el-select>
        </el-form-item>
      </el-col>
      <el-col :span="24">
        <el-form-item label="收费说明">
          <el-input v-model="form.detectionFeeExplain" placeholder="" size="mini"></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item label="附加费">
          <el-input v-model="form.attachedFee" placeholder="" size="mini"></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="18">
        <el-form-item label="附加费说明">
          <el-input v-model="form.attachedFeeExplain" placeholder="" size="mini"></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="24">授权信息</el-col>
      <el-col :span="6">
        <el-form-item label="授权检定">
          <el-select v-model="form.isVerifyAuthName" placeholder="" size="mini">
            <el-option key="'isVerifyAuthName' + 1" label="是" value="1"></el-option>
            <el-option key="'isVerifyAuthName' + 0" label="否" value="0"></el-option>
          </el-select>
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item label="授权校准">
          <el-select v-model="form.isCalibrationAuth" placeholder="" size="mini">
            <el-option key="'isCalibrationAuth' + 1" label="是" value="1"></el-option>
            <el-option key="'isCalibrationAuth' + 0" label="否" value="0"></el-option>
          </el-select>
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item label="授权cnas">
          <el-select v-model="form.isCnasAuth" placeholder="" size="mini">
            <el-option key="'isCnasAuth' + 1" label="是" value="1"></el-option>
            <el-option key="'isCnasAuth' + 0" label="否" value="0"></el-option>
          </el-select>
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item label="服务类型">
          <el-select v-model="form.certificateType" placeholder="" size="mini">
            <el-option key="'certificateType' + 1" label="检定" value="1"></el-option>
            <el-option key="'certificateType' + 2" label="校准" value="2"></el-option>
            <el-option key="'certificateType' + 3" label="检测" value="2"></el-option>
            <el-option key="'certificateType' + 4" label="测试" value="2"></el-option>
            <el-option key="'certificateType' + 5" label="其他" value="2"></el-option>
          </el-select>
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item label="授权测试">
          <el-select v-model="form.isTestAuth" placeholder="" size="mini">
            <el-option key="'isTestAuth' + 1" label="是" value="1"></el-option>
            <el-option key="'isTestAuth' + 0" label="否" value="0"></el-option>
          </el-select>
        </el-form-item>
      </el-col>
      <el-col :span="24">强检信息</el-col>
      <el-col :span="6">
        <el-form-item label="是否强检">
          <el-select v-model="form.isForce" placeholder="" size="mini">
            <el-option key="'isForce' + 0" label="否" value="0"></el-option>
            <el-option key="'isForce' + 1" label="是" value="1"></el-option>
          </el-select>
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item label="器具用途">
          <el-select v-model="form.useType" placeholder="" size="mini">
            <el-option key="'useType' + 1" label="司法鉴定" value="1"></el-option>
            <el-option key="'useType' + 2" label="环境监测" value="2"></el-option>
            <el-option key="'useType' + 3" label="部门和企业、事业单位最高计量标准器具" value="3"></el-option>
            <el-option key="'useType' + 4" label="社会公用计量标准器具" value="4"></el-option>
            <el-option key="'useType' + 5" label="医疗卫生" value="5"></el-option>
            <el-option key="'useType' + 6" label="安全防护" value="6"></el-option>
            <el-option key="'useType' + 7" label="贸易结算" value="7"></el-option>
            <el-option key="'useType' + 8" label="行政执法" value="8"></el-option>
            <el-option key="'useType' + 9" label="食品安全" value="9"></el-option>
            <el-option key="'useType' + 10" label="资源管理" value="10"></el-option>
          </el-select>
        </el-form-item>
      </el-col>
      <el-col :span="24">
        <el-form-item>
          <el-button type="primary" @click="handleSubmit">立即创建</el-button>
          <el-button>取消</el-button>
        </el-form-item>
      </el-col>
    </el-form>
  </d2-container>
</template>
<script>
import api from '@/api'

export default {
  name: 'utensil-create',
  created () {
    this.getUtensilTypeList()
    this.getDepartmentList()
  },
  methods: {
    async getUtensilTypeList () {
      var res = await api.BASE_UTENSIL_TYPE_LIST({
        pageNo: 1,
        pageSize: 500
      })
      this.utensilTypeList = res.list
    },
    async getDepartmentList () {
      var res = await api.OA_DEPARTMEN_LIST({
        pageNo: 1,
        pageSize: 100
      })
      this.departmentList = res.list
    },
    handleSubmit () {
      if (this.form.id) {
        api.BASE_UTENSIL_EDIT(this.form).then(res => {
          this.$message({
            message: '添加成功',
            type: 'success'
          })
          this.initForm()
        })
      } else {
        delete this.form.id
        api.BASE_UTENSIL_CRATE(this.form)
      }
    },
    initForm () {
      this.form = {
        id: 0,
        categoryCode: 1,
        applianceName: '',
        model: '',
        measureRange: '',
        accuracyDegree: 1,
        applianceType: '1',
        departId: 1,
        detectionMethod: '1',
        detectionParameter: '',
        detectionDuration: '',
        status: '1',
        certificateJdzq: '1',
        isSubpackage: '0',
        remark: '',
        detectionFee: '',
        detectionPoint: '',
        chargeUnit: '',
        isDiscount: '1',
        detectionFeeExplain: '',
        attachedFee: '',
        attachedFeeExplain: '',
        isVerifyAuthName: '0',
        isCalibrationAuth: '0',
        isCnasAuth: '0',
        certificateType: '1',
        isTestAuth: '1',
        isForce: '0',
        useType: '3'
      }
    }
  },
  data () {
    return {
      utensilTypeList: [],
      departmentList: [],
      form: {
        id: 0,
        categoryCode: 1,
        applianceName: '',
        model: '',
        measureRange: '',
        accuracyDegree: 1,
        applianceType: '1',
        departId: 1,
        detectionMethod: '1',
        detectionParameter: '',
        detectionDuration: '',
        status: '1',
        certificateJdzq: '1',
        isSubpackage: '0',
        remark: '',
        detectionFee: '',
        detectionPoint: '',
        chargeUnit: '',
        isDiscount: '1',
        detectionFeeExplain: '',
        attachedFee: '',
        attachedFeeExplain: '',
        isVerifyAuthName: '0',
        isCalibrationAuth: '0',
        isCnasAuth: '0',
        certificateType: '1',
        isTestAuth: '1',
        isForce: '0',
        useType: '3'
      }
    }
  }
}
</script>
